using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using Ezio.Models;

namespace Ezio.Controllers
{
    public class ProgramacionMenusController : Controller
    {
        DataProvider Provider = new DataProvider();

        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult Agregar(ProgramacionMenus ProgramacionMenu)
        {
            ProgramacionMenu.ElaboradoPor = HttpContext.User.Identity.Name;
            Provider.AddToProgramacionMenus(ProgramacionMenu);
            return RedirectToAction("Index", new { Success = Provider.TrySaveChanges() });
        }
        public ActionResult Index(bool? Success)
        {
            string Message = Success.HasValue ? Success.Value ? "" : "Ha ocurrido un error al procesar su peticion" : "";

            ViewData["ProgramacionMenus"] = Provider.ProgramacionMenus.ToList();
            ViewData["Colegios"] = Provider.Colegios.ToList();
            ViewData["Menus"] = Provider.Menus.ToList();
            ViewData["Message"] = Message;
            return View("Index");
        }
        public ActionResult Editar(int Id)
        {
            ViewData["ProgramacionMenu"] = Provider.ProgramacionMenus.Single(t => t.IdProgramacionMenu == Id);
            return View();
        }

        [AcceptVerbs(HttpVerbs.Post)]
        public bool Update(ProgramacionMenus ProgramacionMenu)
        {
            ProgramacionMenus myProgramacionMenu = Provider.ProgramacionMenus.Single(t => t.IdProgramacionMenu == ProgramacionMenu.IdProgramacionMenu);
            myProgramacionMenu.Copy(ProgramacionMenu);
            return Provider.TrySaveChanges();
        }

        [AcceptVerbs(HttpVerbs.Post)]
        public List<ProgramacionMenus> GetByColegio(int IdColegio)
        {
            return Provider.ProgramacionMenus.Where(t => t.IdColegio == IdColegio).ToList();
        }
    }
}
